package com.itheima.service.impl;

import com.itheima.mapper.ReportMapper;
import com.itheima.pojo.Report;
import com.itheima.pojo.Setmeal;
import com.itheima.pojo.SetmealCount;
import com.itheima.pojo.hotSetmeal;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;

@Service
@Transactional(rollbackFor = Exception.class)
public class ReportServiceImpl implements ReportService {

    @Autowired
    private ReportMapper reportMapper;

    @Override
    public Report getBusinessReportData() {
        Random rnd = new Random();
        Report report = reportMapper.getBusinessReportData();
        List<hotSetmeal> hotSetmeal = reportMapper.getHotSetmeal();
        for (int i = 0; i < hotSetmeal.size(); i++) {
            int num = rnd.nextInt(5) + 1;
            hotSetmeal.get(i).setSetmeal_count(num);
            hotSetmeal.get(i).setProportion(String.format("%.2f%%", (num * 1.0 / report.getTotalMember())*10));
        }
        report.setHotSetmeal(hotSetmeal);
        return report;
    }



    @Override
    public List<LocalDate> getMemberReportMonth(LocalDate start, LocalDate end) {
        return reportMapper.getMemberReportMonth(start, end);
    }

    @Override
    public List<Integer> getMemberReport(List<LocalDate> months) {
        List<Integer> memberCount = reportMapper.getMemberReport(months);
        return memberCount ;
    }

    @Override
    public List<Setmeal> getSetmealReport() {
        return reportMapper.getSetmealReport();
    }

    @Override
    public List<SetmealCount> getSetmealReportCount() {
        return reportMapper.getSetmealReportCount();
    }


}
